<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="demo-form-inline">
      <el-form-item label="区块编号">
        <el-input v-model="queryParams.blockNumber" placeholder="区块编号" />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
   
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
  
      <el-table-column label="区块编号" align="center" prop="blockNumber">

      </el-table-column>
      <el-table-column label="大小" align="center" prop="checkoutStatus1">

      </el-table-column>
      <el-table-column label="单双" align="center" prop="checkoutStatus2	">

      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createdTime">
      </el-table-column>
      <el-table-column label="是否整秒" align="center" prop="isWholeSecond">

      </el-table-column>
      <el-table-column label="分表时间" align="center" prop="shardingTime"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleShowInfo(scope.row)">查看</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <Add ref="add" />
    <ShowInfo ref="ShowInfo" />
  </div>
</template>

<script>
import { blockList, productUserEnable } from '@/api/table'
import Add from './add.vue'
import ShowInfo from './showInfo.vue'
export default {
  components: {
    Add,
    ShowInfo
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      date: [],
      statusOptions: [
        { label: '下架', value: '0' },
        { label: '上架', value: '1' }
      ],
      typeOptions: [
        { label: '限购份数', value: 'limit_number' },
        { label: '限购金额', value: 'limit_money' }
      ],
      queryParams: {
        'blockNumber': '',
        'pageNum': 1,
        'pageSize': 10,
       
      }
    }
  },
  created() {
    this.fetchData()
  },
  mounted() {

  },
  methods: {
    handleShowInfo(e){
      this.$refs.ShowInfo.show(e)
    },
    async setStatus(user) {
      let status = ''
      if (user.status === 1) {
        status = 0
      } else {
        status = 1
      }
      await productUserEnable({ id: user.id, status: status })
      this.fetchData()
      this.$message({
        message: '操作成功',
        type: 'success'
      })
    },
    fetchData() {
      this.listLoading = true
      blockList(this.queryParams).then(response => {
        response.data.records.map(item => {
          if (item.status === 1) {
            item.statusB = true
          } else {
            item.statusB = false
          }
          console.log(item.statusB)
        })
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },

    onSubmit() {
      this.queryParams.pageNum = 1

      this.fetchData()
    },
    handleAdd() {
      this.$refs.add.show()
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    },
    handleshowInfo(e) {
      this.$refs.ShowInfo.show(e)
    },
    reset() {
      this.value1 = ''
      this.value2 = ''
      this.queryParams = {
        'blockNumber': '',
        'pageNum': 1,
        'pageSize': 10,
      }
      this.fetchData()
    }

  }
}
</script>
